在 Playground 中编译 SwiftUI 的代码
记录下在 Playground 中编译 SwiftUI 的代码。
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var counter = 0
var body: some View {
VStack {
Button(action: { self.counter += 1 }, label: {
Text("Tap me!")
.padding()
.background(Color(.tertiarySystemFill))
.cornerRadius(5)
})
if counter > 0 {
Text("You've tapped \(counter) times")
} else {
Text("You've not yet tapped")
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
